package com.lanou.sfu.songforu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lanou.sfu.songforu.R;
import com.lanou.sfu.songforu.datas.SearchSinger;
import com.lanou.sfu.songforu.tools.CircleImageView;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by quyan on 15/10/29.
 */
public class SearchSingerAdapter extends BaseAdapter {
    private List<SearchSinger.DataEntity>datas;
    private Context context;

    public SearchSingerAdapter(Context context, List<SearchSinger.DataEntity> dataEntities) {
        this.context = context;
        this.datas = dataEntities;
    }

    @Override
    public int getCount() {
        return datas != null && datas.size() > 0 ? datas.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.search_singer_content,null);
            holder = new ViewHolder();
            holder.albunNum = (TextView) convertView.findViewById(R.id.album_num);
            holder.singerCircle = (CircleImageView) convertView.findViewById(R.id.singer_circle);
            holder.singerName = (TextView) convertView.findViewById(R.id.singer_name);
            holder.songNum = (TextView) convertView.findViewById(R.id.song_num);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        SearchSinger.DataEntity dataEntity = (SearchSinger.DataEntity) getItem(position);
        holder.singerName.setText(dataEntity.getSinger_name());
        holder.albunNum.setText(dataEntity.getAlbum_num());
        holder.songNum.setText(dataEntity.getSong_num());
        Picasso.with(context).load(dataEntity.getPic_url()).into(holder.singerCircle);
        return convertView;
    }

    public class ViewHolder{
        private CircleImageView singerCircle;
        private TextView singerName;
        private TextView songNum;
        private TextView albunNum;
    }
}
